#ifndef AIQA_WIDGET_H
#define AIQA_WIDGET_H

#include <QWidget>
#include <QTextEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QScrollArea>
#include <QResizeEvent>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QTimer>
#include <QLabel>
#include <QFileDialog>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui { class AiqaWidget; }
QT_END_NAMESPACE

class AiqaWidget : public QWidget
{
    Q_OBJECT

public:
    AiqaWidget(QWidget *parent = nullptr);
    ~AiqaWidget();

private slots:
    void onSendClicked();
    void onReferenceFileClicked();
    void onDeepThinkClicked();
    void onAiResponseReceived(QNetworkReply *reply);
    void updateThinkingAnimation();
    void onRequestTimeout();

private:
    Ui::AiqaWidget *ui;

    QTextEdit *inputTextEdit;
    QWidget *chatContainer;
    QVBoxLayout *chatLayout;
    QNetworkAccessManager *networkManager;
    QString currentQuestion;
    QTimer *thinkingTimer;
    int thinkingDotCount;
    QLabel *thinkingBubble;
    QWidget *thinkingWidget;
    QTimer *requestTimeoutTimer;

    // 新增：模式状态
    bool isDeepThinkMode;          // 深度思考模式标志
    QStringList referencedFiles;   // 引用的文件列表

    // API配置
    const QString API_KEY = "5ed5182f10bc4c84a9f4ae8b25a29bfa.bvIUFYaNKYmnkfmb";
    const QString API_URL = "https://open.bigmodel.cn/api/paas/v4/chat/completions";
    const QString MODEL_NAME = "glm-4";

    void addUserMessage(const QString &message);
    void addAiMessage(const QString &message);
    void addSystemMessage(const QString &message);
    void addLoadingMessage();
    void removeLoadingMessage();
    void clearChat();
    void processAIResponse(const QString &question);
    void sendRequestToAI(const QString &question);

    // 新增：文件处理函数
    void addFileReference(const QString &filePath);
    void removeFileReference(int index);
    void updateFileReferencesDisplay();

protected:
    void resizeEvent(QResizeEvent *event) override;
};

#endif // AIQA_WIDGET_H
